<?php
/**
 * Create a Dunning Message for each user sent
 *
 */

use Fox\Note;
$values = Xview::instance()->val("value");
if(!empty($values))
{
	$userIds = preg_split("/:/",$values,null,PREG_SPLIT_NO_EMPTY);
	try {
		$date = new DateTime(Xview::instance()->val("date"));
		foreach($userIds as $id)
		{
			$note = new Note();
			$fields['nottp'] = Note::TYPE_INFO;
			$fields['msgcl'] = "MSG";
			$fields['msgid'] = 13;
			$fields['subject'] = Msg("MSG",13,$date->format("m"),$date->format("Y"));
			$fields['body'] 	= Msg("MSG",13,$date->format("m"),$date->format("Y"));
			$fields['params'] = $date->format("m").":".$date->format("Y");
			$fields['target'] = $id;
			$note->setFields($fields);
			$note->create();
		}
		echo Fox\Message::Success(Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_CREATE,$fields['subject']));
	}
	catch (Fox\Object\Exception\Save $e)
	{
		echo Fox\Message::Error($e->getMessage());
	}
}